package com.baosight.risk.web.riaa;


import com.baosight.risk.api.riaa.RiaaEvaluateService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.base.entity.MultipleUpdateStatus;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.enums.BusinessType;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.riaa.entity.RiaaEvaluate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * 类 名: RiaaEvaluateController
 * 描 述: 能力测评配置
 * 作 者: 黎秋荣
 * 创 建：2019年07月26日
 * 版 本：v2.2.0
 * 历 史: (版本) 作者 时间 注释
 */
@Slf4j
@RestController
@RequestMapping("/riaa/evaluate")
@Api(value = "能力测评配置", description = "能力测评配置", produces = MediaType.APPLICATION_JSON)
public class RiaaEvaluateController extends BaseController {

    @Autowired
    private RiaaEvaluateService evaluateService;


    @PostMapping("selectFieldList")
    @ApiOperation("查询管理领域列表")
    public AjaxResult selectFieldList(@RequestBody RiaaEvaluate riaaEvaluate) {
        log.info("查询管理领域列表：" + riaaEvaluate.toString());
        return getResultPage(evaluateService.selectFieldList(riaaEvaluate));
    }

    @GetMapping("selectDetailList")
    @ApiOperation("根据管理领域查询测评标准")
    public AjaxResult selectDetailList(String parentId) {
        log.info("根据管理领域查询测评标准：" + parentId);
        return getResultPage(evaluateService.selectDetailList(parentId));
    }

    @PostMapping("saveEvaluate")
    @Log(title = "保存管理目标/测评标准", businessType = BusinessType.UPDATE)
    @ApiOperation("保存管理目标/测评标准")
    public AjaxResult saveEvaluate(@RequestBody List<RiaaEvaluate> riaaEvaluateList) {
        if (CollectionUtils.isEmpty(riaaEvaluateList)) {
            log.error("数据有误！");
            return error("数据有误！");
        }
        log.info("保存管理目标/测评标准：" + riaaEvaluateList.toString());
        return success(evaluateService.saveEvaluate(riaaEvaluateList));
    }

    @PostMapping("deleteByIds")
    @Log(title = "删除管理目标/测评标准", businessType = BusinessType.DELETE)
    @ApiOperation("删除管理目标/测评标准")
    public AjaxResult deleteByIds(@RequestBody MultipleUpdateStatus updateStatus) {
        if (CollectionUtils.isEmpty(updateStatus.getIds())) {
            log.error("数据有误！");
            return error("数据有误！");
        }
        log.info("保存管理目标/测评标准：" + updateStatus.toString());
        return success(evaluateService.deleteByIds(updateStatus));
    }

}
